<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/common/_taglibs.jsp"%>
<%@ include file="/common/_meta.jsp"%>
<title>添加角色-角色管理</title>
<meta name="keywords" content="cms-simple CMS后台管理系统">
<meta name="description" content="cms-simple CMS后台管理系统">
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add" action="${ctx }/sys/addRole" method="post" onsubmit="return onCheck();">
	<input type="hidden" name="id" value="${role.id }"/>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${role.name }" placeholder="" id="name" name="name">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色描述：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${role.description }" placeholder="" id="description" name="description">
		</div>
	</div>
	<div class="row cl">
		<input type="hidden" id="resources" name="resources" />
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色资源：</label>
		<div class="formControls col-xs-8 col-sm-9 zTreeDemoBackground left">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
	</div>
	<div class="row cl">
	<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
		<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
	</div>
	</div>
	</form>
</article>
<script type="text/javascript" src="${ctx }/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctx }/lib/jquery/1.9.1/jquery.form.js"></script> 
<script type="text/javascript" src="${ctx }/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="${ctx }/lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/messages_zh.min.js"></script>
<script type="text/javascript" src="${ctx }/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="${ctx }/static/h-ui.admin/js/H-ui.admin.js"></script> 
<script type="text/javascript" src="${ctx }/lib/zTree/v3/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="${ctx }/lib/zTree/v3/js/jquery.ztree.excheck-3.5.js"></script>
<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript">
$(function(){
	
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-add").validate({
		rules:{
			loginCode:{
				required:true,
				minlength:6,
				maxlength:20
			},
			roleName:{
				required:true,
				minlength:4,
				maxlength:10
			},
			password:{
				required:true,
			},
			password2:{
				required:true,
				equalTo: "#password"
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit();
			var index = parent.layer.getFrameIndex(window.name);
			parent.$('.btn-refresh').click();
			parent.layer.close(index);
		}
	});
});

var setting = {
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true,
				idKey: "id",
				pIdKey: "pid",
				rootPId: 0
			}
		}
	};
	
	var zNodes = ${resourceList };
	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
	});
	
	function onCheck(){
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var nodes = treeObj.getCheckedNodes(true);
		var length = nodes.length;
		var resources = new Array();
		if(nodes != null && length > 0){
			for(var i=0; i<length; i++){
				resources.push(nodes[i]["id"]);
			};
		};
		$("#resources").val(resources);
	};
	
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
